package com.lechi.iot.netty.handle;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TcpExceptionHandler extends ChannelDuplexHandler {

    private String protocol;

    public TcpExceptionHandler(String protocol) {
        this.protocol = protocol;
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        String address = ctx.channel().remoteAddress().toString();
        //由Tail节点对异常进行统一处理
        log.error("网关:{} 设备地址：{}， 处理业务异常：{}", this.protocol, address, cause.getMessage());
//        ctx.close();
        super.exceptionCaught(ctx, cause);
    }
}
